package ${packagePath};

import cn.hutool.core.date.DateUtil;
import pers.cz.mapper.${capsTableName}Mapper;
import pers.cz.model.${capsTableName};
import pers.cz.model.${capsTableName}Example;
import pers.cz.mybatisPlugin.PageRowBounds;
import pers.cz.pub.AbstractBusiness;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 定时任务业务实现类
 * @program: PostGirl-panent
 * @description: TaskJobBusiness
 * @author: Cheng Zhi
 * @create: 2021-04-26 20:36
 **/
public class ${capsTableName}Business extends AbstractBusiness {

    /**
     * 添加${capsTableName}
     * @param ${lowerTableName}
     * @return
     */
    public int add${capsTableName}(${capsTableName} ${lowerTableName}) {

        int count = this.getMapper().getBean(${capsTableName}Mapper.class).insert(${lowerTableName});

        return count;
    }

    public List<${capsTableName}> findList(${capsTableName} ${lowerTableName}) {

        ${capsTableName}Example example = this.createExample(${lowerTableName});
        List<${capsTableName}> list = this.getMapper().getBean(${capsTableName}Mapper.class).selectByExample(example);
        return list;
    }

    public int delete(${keyType} id) {

        return this.getMapper().getBean(${capsTableName}Mapper.class).deleteByPrimaryKey(id);
    }

    public int update(${capsTableName} ${lowerTableName}) {

        ${capsTableName}Example example = this.createExample(${lowerTableName});
        return this.getMapper().getBean(${capsTableName}Mapper.class).updateByExampleSelective(${lowerTableName}, example);
    }

    public ${capsTableName} findById(${keyType} id) {
        ${capsTableName} ${lowerTableName} = this.getMapper().getBean(${capsTableName}Mapper.class).selectByPrimaryKey(id);
        return ${lowerTableName};
    }

    public List<${capsTableName}> findAll() {
        ${capsTableName} ${lowerTableName} = new ${capsTableName}();
        ${capsTableName}Example example = this.createExample(${lowerTableName});
        return this.getMapper().getBean(${capsTableName}Mapper.class).selectByExample(example);
    }

    /**
     * ${capsTableName}构建查询对象
     * @param ${lowerTableName}
     * @return
     */
    public ${capsTableName}Example createExample(${capsTableName} ${lowerTableName}){
        ${capsTableName}Example example = new ${capsTableName}Example();
        ${capsTableName}Example.Criteria criteria = example.createCriteria();
        if(${lowerTableName}!=null){
        <#list columns as md>
            if(!StringUtils.isEmpty(${lowerTableName}.get${md}())){
                criteria.and${md}EqualTo(${lowerTableName}.get${md}());
            }
        </#list>
        }
        return example;
    }
}
